package com.group.eams.controller.student;

import com.group.eams.entity.Student;
import com.group.eams.service.IRecruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by Doctor Who on 2016/11/3.
 */
@Controller
@RequestMapping("/recruitstudent/recruitstudent")
public class RecruitStudentController {
    private IRecruitService recruitService;

    @Autowired
    public RecruitStudentController(IRecruitService recruitService){
        this.recruitService = recruitService;
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Model model){
        List<Student> recruitList = recruitService.getAllRecruitStudent();
        model.addAttribute("list",recruitList);
        return "recruitstudent/recruitstudent/listRecruitStudent";
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST)
    public String query(Student student, Model model){
        List<Student> recruitList = recruitService.getRecruitStudent(student);
        model.addAttribute("list",recruitList);
        return "recruitstudent/recruitstudent/listRecruitStudent";
    }
    @RequestMapping(value = "/delRecruitStudent", method = RequestMethod.GET)
    public String delRecruitStudent(Student student, Integer id, Model model){
        if (student == null){
            student = new Student();
        }
        student.setId(id);
        student.setIntention(-1); //-1表示无意向，0表示低，1表示中，2表示高
        boolean mark = recruitService.delRecruitStudent(student);
        if (mark){
            model.addAttribute("info", "删除学员成功！");
        }else{
            model.addAttribute("info","删除学员失败！");
        }
        return list(model);
    }

    @RequestMapping(value = "/toChange")
    public String toChange(){
        return "/recruitstudent/recruitstudent/updateRecruitStudent";
    }

    @RequestMapping(value = "/toAdd")
    public String toAdd(){
        return "/recruitstudent/recruitstudent/addRecruitStudent";
    }
}
